<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/component/commonTagLib.jsp" %>

<!DOCTYPE html>
<html>
<head>
    <title><spring:message code="message.lable.role" /></title>
    <%@ include file="/WEB-INF/component/commonCSS.jsp" %>
    <style type="text/css">
        div.privDiv {
            margin: 10px;
        }
        table.privTable {
            width: 100%;
            height: 100%;
            border-collapse: collapse;
        }
        table.privTable th {
            background-color: #F9F9F9;
        }
        table.privTable tr {
            background-color: #fff;
        }
        table.privTable th, table.privTable td {
            border: 1px solid #e2e2e2;
            height: 30px;
            font-weight: normal;
            padding-left: 10px;
            padding-right: 10px;
        }
        th, td.center {
            text-align: center;
        }
        table.privTable td * {
            vertical-align: middle;
            font-weight: normal;
        }
        table.privTable td label {
            margin: 3px 5px;
        }
        table.privTable td input {
            margin: 0px 5px;
        }
        i.fa {
            line-height: 1.42857;
        }
        span.space {
            height: 10px;
            display: inline-block;
        }
        span.line {
            width: 30px;
            height: 30px;
            display: inline-block;
            background: url('${ctx}/lib/img/icon/treeLine .png') no-repeat 10px 5px;
        }
        div.modal-footer {
            position: fixed;
            bottom: 0px;
            width: 100%;
            background-color: #fff;
        }
    </style>
</head>
<body style="background-color:#ecf0f5;">
  <div class="privDiv">
        <table id="privTable" class="privTable">
            <tr>
                <th width="300px"><spring:message code="message.label.navigation" /></th>
                <th width="50px"><spring:message code="message.label.all" /></th>
                <th width="*"><spring:message code="message.label.permissionAssignment" /></th>
            </tr>
        </table>
    </div>
    
    <table id="tempTable" style="display:none;">
        <tr id="temp">
            <td>
                <span class="space"></span>
                <span class="line"></span>
                <i class="fa"></i>
                <span class="name"></span>
            </td>
            <td class="center">
                <input type="checkbox" class="all" />
            </td>
            <td class="btnTd"><label><input type="checkbox" class="menu" /><span><spring:message code="message.label.show" /></span></label></td>
        </tr>
    </table>
    
    <div style="height:55px;"></div>
    
    <div class="modal-footer">
        <button onclick="closeDialog();" class="btn btn-danger btn-sm" type="button"><spring:message code="message.button.closeSpacing" /></button>
    </div>
    
    <%@ include file="/WEB-INF/component/commonJS.jsp" %>
    
    <script type="text/javascript">
        function closeDialog() {
            var dialog = top.dialog.get(window);
            // dialog.close("params"); // 关闭（隐藏）对话框
            dialog.remove(); // 主动销毁对话框
        }
    
        $(function () {
            
        	// 展示权限列表
            function showPrevList(list, level, $pTr) {
                if (list != null && list.length > 0) {
                    for (var i=0; i<list.length; i++) {
                        var priv = list[i];
                        if (priv.type == 0 || priv.type == 1 || priv.type == 2 ) {
                            var $tr = $("#temp").clone().removeAttr("id");
                            $tr.find("i.fa").addClass(priv.icon || "fa fa-genderless");
                            $tr.find("span.name").text(priv.menuName || "");
                            var width = 30 * (level - 1);
                            $tr.find("span.space").css("width", width + "px");
                            $("#privTable").append($tr);
                            if (priv.children != null && priv.children.length > 0) {
                            	// 递归模块和菜单
                                showPrevList(priv.children, level + 1, $tr);
                            }
                        } else if (priv.type == 3 && $pTr) {
                            var $btn = $('<label><input type="checkbox" /><span>' + priv.menuName + '</span></label>');
                            $pTr.find("td.btnTd").append($btn);
                        }
                    }
                }
            }
            
            $.post("${ctx}/sysPrivilege/getMainRolePrivilege.html", {
                "roleId" : "${roleId}"
            }, function(result) {
                if (result.success) {
                    showPrevList(result.rows, 1);
                    
                    $("#privTable input[type='checkbox']").prop("checked", true);
                    $("#privTable input[type='checkbox']").prop("disabled", true);
                }
            }, "json");
            
        });
    </script>
</body>
</html>












